package com.ruoyi.web.controller.app;

import com.ruoyi.business.domain.TProductReview;
import com.ruoyi.business.service.ITProductReviewService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * App端 商品评价接口
 *
 * @author laoguo
 */
@RestController
@RequestMapping("/app/review")
public class AppReviewController extends BaseController {

    @Autowired
    private ITProductReviewService reviewService;

    /**
     * 提交商品评价
     */
    @PostMapping("/submit")
    public AjaxResult submitReview(@Validated @RequestBody TProductReview review) {
        // 调用Service层处理提交逻辑
        reviewService.submitReview(review);
        return AjaxResult.success("评价成功");
    }

    /**
     * 分页获取某个商品的评价列表
     */
    @GetMapping("/list/{productId}")
    public TableDataInfo listReviews(@PathVariable("productId") Long productId) {
        TProductReview queryParam = new TProductReview();
        queryParam.setProductId(productId);
        queryParam.setStatus("0"); // 只查询显示的评价

        startPage();
        List<TProductReview> list = reviewService.selectTProductReviewList(queryParam);
        return getDataTable(list);
    }
}